// page-personalInformationImg/home.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    infoData: {},
    enterprise: { sfzqm: '法人身份证正面', sfzbm: '法人身份证背面', hukou: '法人户口簿', peiouhukou: '营业执照副本', jiehunzheng: '介绍信', rentou: '代办人照片' ,otherIdentityPositive:'代理人身份证正面', otherIdentityOpposite:'代理人身份证背面'},
    my: { sfzqm: '身份证正面', sfzbm: '身份证背面照', rentou: '申请人照片', hukou: '申请人户口本', jiehunzheng: '婚姻证明', peiouhukou: '配偶户口簿', otherIdentityPositive: '配偶身份证正面', otherIdentityOpposite: '配偶身份证背面'},
    url: 'https://www.gcjxglzx.com/upload/uploadImgTest',
    path: '',//文件本地路径
    name: '',//name标识符
    pathType: '',//自定义上传的目录路径
    identityNum: '',//身份证号
    sfzqm: app.globalData.operationImage[0], //身份证正面/法人身份证正面
    sfzbm: app.globalData.operationImage[1], //身份证背面/法人身份证背面
    rentou: app.globalData.operationImage[2], //申请人照片/代办人照片
    hukou: app.globalData.operationImage[3], //申请人户口簿/法人户口簿
    peiouhukou: app.globalData.operationImage[4], //配偶户口簿//营业执照副本
    jiehunzheng: app.globalData.operationImage[5], //婚姻证明/介绍信
    otherIdentityPositive:'',//配偶身份证正面/代理人身份证正面 
    otherIdentityOpposite:'',//配偶身份证背面/代理人身份证背面 
    maritalStatus:'',//婚姻状况
    userType:'',//0个人，   1企业
    qylxr: false,
    marriage: false,
    hyzm:true
  },
  chooseImage: function (e) {
    console.log(e.target.id)
    var self = this;
    wx.chooseImage({
      count: 1,
      sourceType: ['camera'],
      success: function (res) {
        if (e.target.id == '0') {
          self.setData({
            name: "sfzqm"
          });
          self.setData({
            sfzqm: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.identityNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              sfzqm: imgResponseUrl
            })
          };
        } else if (e.target.id == '1') {
          self.setData({
            name: "sfzbm"
          });
          self.setData({
            sfzbm: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.identityNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              sfzbm: imgResponseUrl
            })
          };
        } else if (e.target.id == '2') {
          self.setData({
            name: "rentou"
          });
          self.setData({
            rentou: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.identityNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              rentou: imgResponseUrl
            })
          };
        } else if (e.target.id == '3') {
          self.setData({
            name: "hukou"
          });
          self.setData({
            hukou: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.identityNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              hukou: imgResponseUrl
            })
          };
        } else if (e.target.id == '4') {
          self.setData({
            name: "peiouhukou"
          });
          self.setData({
            peiouhukou: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.identityNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              peiouhukou: imgResponseUrl
            })
          };
        } else if (e.target.id == '5') {
          self.setData({
            name: "jiehunzheng"
          });
          self.setData({
            jiehunzheng: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.identityNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              jiehunzheng: imgResponseUrl
            })
          };
        } else if (e.target.id == '6') {
          self.setData({
            name: "qtsfzqm"
          });
          self.setData({
            otherIdentityPositive: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.identityNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              otherIdentityPositive: imgResponseUrl
            })
          };
        } else if (e.target.id == '7') {
          self.setData({
            name: "qtsfzbm"
          });
          self.setData({
            otherIdentityOpposite: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.identityNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              otherIdentityOpposite: imgResponseUrl
            })
          };
        }
      }
    });
  },
  submit: function (e) {
    var that = this;
    var identityNum = e.detail.value.identityNum;//身份证号
    var identityPositiveImg = that.data.sfzqm; //身份证正面照
    var identityOppositeImg = that.data.sfzbm; //身份证背面照
    var portrait = that.data.rentou; //本人彩照
    var householdRegisterImg = that.data.hukou; //本人户口本资料页照片
    var householdSpouseImg = that.data.peiouhukou; //配偶户口本资料页照片
    var marriageCertificate = that.data.jiehunzheng; //结婚证照片
    var otherIdentityPositive = that.data.otherIdentityPositive;
    var otherIdentityOpposite = that.data.otherIdentityOpposite
    wx.request({
      url: 'https://www.gcjxglzx.com/personalInformationImg/save',
      method: 'POST',
      data: {
        identityNum: identityNum,
        identityPositiveImg: identityPositiveImg,
        identityOppositeImg: identityOppositeImg,
        portrait: portrait,
        householdRegisterImg: householdRegisterImg,
        householdSpouseImg: householdSpouseImg,
        marriageCertificate: marriageCertificate,
        otherIdentityPositive: otherIdentityPositive,
        otherIdentityOpposite: otherIdentityOpposite
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data)

        wx.navigateBack({
          delta: 3
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      identityNum: options.identification,
      maritalStatus: wx.getStorageSync("marryStatus"),
      userType: wx.getStorageSync("userType")
    });
    if (this.data.userType == '1'){
      this.setData({
        infoData: this.data.enterprise,
        marriage:true
      })
    }
    if (this.data.userType == '0'){
      this.setData({
        infoData: this.data.my
      })
      if (this.data.maritalStatus == '0'){
        this.setData({
          marriage: true
        })
      }
      if (this.data.maritalStatus == '1') {
        this.setData({
          hyzm: false,
          marriage: false
        })
      }
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})